<div navbar ng-init="currentItem='utils.cron'"></div>
<div ng-hide="loaded">
    <div loading></div>
</div>

<div id="main" ng-init="load()" ng-show="loaded">
    <div class="module-header">
        <h3>定时任务管理</h3>
    </div>
    <div class="well" ng-hide="has_cron_service">
        <p>系统检测到 Cron 当前尚未安装。</p>
        <p>是否要开始安装？</p>
        <p><a class="btn btn-default" href="#/service/cron">立即安装</a></p>
    </div>
    <div class="tabbable">
        <ul class="nav nav-tabs">
            <li ng-class="'active' | iftrue:activeTabName=='normal'"><a href="#normal" ng-click="tab_sec('normal')" data-toggle="tab">普通任务</a></li>
            <li ng-class="'active' | iftrue:activeTabName=='system'"><a href="#system" ng-click="tab_sec('system')" data-toggle="tab">系统任务</a></li>
            <li ng-class="'active' | iftrue:activeTabName=='environment'"><a href="#environment" ng-click="tab_sec('environment')" data-toggle="tab">环境变量</a></li>
            <li ng-class="'active' | iftrue:activeTabName=='local'"><a href="#local" ng-click="tab_sec('local')" data-toggle="tab">本地任务</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='normal'" id="normal">
                <div ng-show="loading.normal">
                    <div waiting></div>
                </div>
                <div ng-show="!loading.normal">
                    <div class="row">
                        <div class="col-md-6 col-sm-6 col-xs-5">
                            <h5>普通任务列表</h5>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-7">
                            <div class="form-inline pull-right">
                                <select class="form-control input-sm" ng-model="cron_normal.user" ng-change="load_normal_list()" ng-options="user for user in users" style="display: inline-block;width: 100px;"></select>
                                <div class="btn-group btn-group-sm">
                                    <button class="btn btn-default" title="刷新列表" ng-disabled="!loaded" ng-click="load_normal_list()"><i class="glyphicon glyphicon-refresh"></i></button>
                                    <button class="btn btn-default" title="添加任务" ng-disabled="!loaded" ng-click="add_cron_normal()"><i class="glyphicon glyphicon-plus"></i></button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table class="table table-hover table-bordered table-condensed">
                        <thead>
                            <tr>
                                <th style="width: 50px;">ID</th>
                                <th style="width: 50px;">分钟</th>
                                <th style="width: 50px;">小时</th>
                                <th style="width: 50px;">天</th>
                                <th style="width: 50px;">月份</th>
                                <th style="width: 65px;">工作日</th>
                                <th style="width: 65px;">用户</th>
                                <th>命令</th>
                                <th style="width: 100px;">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-show="cron_normal.list.length < 1">
                                <td colspan="9">当前列表任务为空</td>
                            </tr>
                            <tr ng-repeat="info in cron_normal.list">
                                <td>{{info.id}}</td>
                                <td>{{info.minute}}</td>
                                <td>{{info.hour}}</td>
                                <td>{{info.day}}</td>
                                <td>{{info.month}}</td>
                                <td>{{info.weekday}}</td>
                                <td>{{info.user}}</td>
                                <td><code>{{info.command}}</code></td>
                                <td>
                                    <button class="btn btn-default btn-xs" ng-click="cron_detail(info, 'normal')">查看</button>
                                    <button class="btn btn-default btn-xs" ng-click="cron_del_confirm(info, 'normal')">删除</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='system'" id="system">
                <div ng-show="loading.system"><div waiting></div></div>
                <div ng-show="!loading.system">
                    <div class="row">
                        <div class="col-md-6 col-sm-6 col-xs-5">
                            <h5>系统任务列表</h5>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-7">
                            <div class="form-inline pull-right">
                                <select class="form-control input-sm" ng-model="cron_system.user" ng-change="load_system_list()" ng-options="user for user in users" style="display: inline-block;width: 100px;">
                                    <option value="">全部</option>
                                </select>
                                <div class="btn-group btn-group-sm">
                                    <button class="btn btn-default" title="刷新列表" ng-disabled="!loaded" ng-click="load_system_list()"><i class="glyphicon glyphicon-refresh"></i></button>
                                    <button class="btn btn-default" title="添加任务" ng-disabled="!loaded" ng-click="add_cron_system()"><i class="glyphicon glyphicon-plus"></i></button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table class="table table-hover table-bordered table-condensed">
                        <thead>
                            <tr>
                                <th style="width: 50px;">ID</th>
                                <th style="width: 50px;">分钟</th>
                                <th style="width: 50px;">小时</th>
                                <th style="width: 50px;">天</th>
                                <th style="width: 50px;">月份</th>
                                <th style="width: 65px;">工作日</th>
                                <th style="width: 65px;">用户</th>
                                <th>命令</th>
                                <th style="width: 100px;">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-show="cron_system.list.length < 1">
                                <td colspan="9">当前列表任务为空</td>
                            </tr>
                            <tr ng-repeat="info in cron_system.list">
                                <td>{{info.id}}</td>
                                <td>{{info.minute}}</td>
                                <td>{{info.hour}}</td>
                                <td>{{info.day}}</td>
                                <td>{{info.month}}</td>
                                <td>{{info.weekday}}</td>
                                <td>{{info.user}}</td>
                                <td><code>{{info.command}}</code></td>
                                <td>
                                    <button class="btn btn-default btn-xs" ng-click="cron_detail(info, 'system')">查看</button>
                                    <button class="btn btn-default btn-xs" ng-click="cron_del_confirm(info, 'system')">删除</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='environment'" id="environment">
                <div ng-show="loading.environment"><div waiting></div></div>
                <div ng-show="!loading.environment">
                    <div class="pull-left">
                        <h5>环境变量(未完成)</h5>
                    </div>
                    <div class="pull-right">
                        <div class="btn-group btn-group-sm">
                            <button class="btn btn-default" title="刷新列表" ng-disabled="!loaded" ng-click="load_environment_list()"><i class="glyphicon glyphicon-refresh"></i></button>
                            <button class="btn btn-default" title="添加环境变量" ng-disabled="!loaded" ng-click="add_environment()"><i class="glyphicon glyphicon-plus"></i></button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='local'" id="local">
                <div ng-show="loading.local"><div waiting></div></div>
                <div ng-show="!loading.local">
                    <div class="pull-left">
                        <h5>本地任务(控制面板运行的任务，未完成)</h5>
                    </div>
                    <div class="pull-right">
                        <div class="btn-group btn-group-sm">
                            <button class="btn btn-default" title="刷新列表" ng-disabled="!loaded" ng-click="load_local_list()"><i class="glyphicon glyphicon-refresh"></i></button>
                            <button class="btn btn-default" title="添加本地任务" ng-disabled="!loaded" ng-click="add_cron_local()"><i class="glyphicon glyphicon-plus"></i></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="cron-add-confirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" ng-show="task_id">
                    <span ng-show="task_level=='normal'">查看普通任务</span>
                    <span ng-show="task_level=='system'">查看系统任务</span>
                </h3>
                <h3 class="modal-title" ng-hide="task_id">
                    <span ng-show="task_level=='normal'">添加普通任务</span>
                    <span ng-show="task_level=='system'">添加系统任务</span>
                </h3>
            </div>
            <div class="modal-body">
                <form class="" onsubmit="return false">
                    <div class="form-group">
                        <div class="row">
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <label for="common_options">快速设置</label>
                                <select id="common_options" class="form-control" ng-model="common_options" ng-change="select_common_option()">
                                    <option value="">请选择</option>
                                    <option value="* * * * *">每分钟一次(* * * * *)</option>
                                    <option value="*/5 * * * *">每五分钟一次(*/5 * * * *)</option>
                                    <option value="0,30 * * * *">每小时两次(0,30 * * * *)</option>
                                    <option value="0 * * * *">每小时一次(0 * * * *)</option>
                                    <option value="0 0,12 * * *">每天两次(0 0,12 * * *)</option>
                                    <option value="0 0 * * *">每天一次(0 0 * * *)</option>
                                    <option value="0 0 * * 0">每周一次(0 0 * * 0)</option>
                                    <option value="0 0 1,15 * *">在每月的第 1 日和第 15 日(0 0 1,15 * *)</option>
                                    <option value="0 0 1 * *">每月一次(0 0 1 * *)</option>
                                    <option value="0 0 1 1 *">每年一次(0 0 1 1 *)</option>
                                </select>
                            </div>
                            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <label for="task_email">电子邮箱</label>
                                <input type="text" ng-model="task_email" class="form-control" id="task_email" placeholder="接收通知的电子邮箱地址">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="minute">分钟</label>
                                <input id="minute" ng-model="cron_time.minute" type="text" class="form-control" size="4" ng-change="input_single_option('minute')" placeholder="分钟">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="minute_options">快速选择</label>
                                <select id="minute_options" ng-model="options.minute" class="form-control" ng-change="select_single_option('minute')">
                                    <option value="">请选择</option>
                                    <option value="*">每分钟一次(*)</option>
                                    <option value="*/2">每两分钟一次(*/2)</option>
                                    <option value="*/3">每三分钟一次(*/3)</option>
                                    <option value="*/4">每四分钟一次(*/4)</option>
                                    <option value="*/5">每五分钟一次(*/5)</option>
                                    <option value="*/10">每十分钟一次(*/10)</option>
                                    <option value="*/15">每十五分钟一次(*/15)</option>
                                    <option value="0,30">每三十分钟一次(0,30)</option>
                                    <option value="--" disabled>-- 分钟 --</option>
                                    <option value="0">:00 (整点开始时。) (0)</option>
                                    <option value="1">:01 (1)</option>
                                    <option value="2">:02 (2)</option>
                                    <option value="3">:03 (3)</option>
                                    <option value="4">:04 (4)</option>
                                    <option value="5">:05 (5)</option>
                                    <option value="6">:06 (6)</option>
                                    <option value="7">:07 (7)</option>
                                    <option value="8">:08 (8)</option>
                                    <option value="9">:09 (9)</option>
                                    <option value="10">:10 (10)</option>
                                    <option value="11">:11 (11)</option>
                                    <option value="12">:12 (12)</option>
                                    <option value="13">:13 (13)</option>
                                    <option value="14">:14 (14)</option>
                                    <option value="15">:15 (整点过去一刻钟时。) (15)</option>
                                    <option value="16">:16 (16)</option>
                                    <option value="17">:17 (17)</option>
                                    <option value="18">:18 (18)</option>
                                    <option value="19">:19 (19)</option>
                                    <option value="20">:20 (20)</option>
                                    <option value="21">:21 (21)</option>
                                    <option value="22">:22 (22)</option>
                                    <option value="23">:23 (23)</option>
                                    <option value="24">:24 (24)</option>
                                    <option value="25">:25 (25)</option>
                                    <option value="26">:26 (26)</option>
                                    <option value="27">:27 (27)</option>
                                    <option value="28">:28 (28)</option>
                                    <option value="29">:29 (29)</option>
                                    <option value="30">:30 (整点过去半小时时。) (30)</option>
                                    <option value="31">:31 (31)</option>
                                    <option value="32">:32 (32)</option>
                                    <option value="33">:33 (33)</option>
                                    <option value="34">:34 (34)</option>
                                    <option value="35">:35 (35)</option>
                                    <option value="36">:36 (36)</option>
                                    <option value="37">:37 (37)</option>
                                    <option value="38">:38 (38)</option>
                                    <option value="39">:39 (39)</option>
                                    <option value="40">:40 (40)</option>
                                    <option value="41">:41 (41)</option>
                                    <option value="42">:42 (42)</option>
                                    <option value="43">:43 (43)</option>
                                    <option value="44">:44 (44)</option>
                                    <option value="45">:45 (整点前的一刻钟时。) (45)</option>
                                    <option value="46">:46 (46)</option>
                                    <option value="47">:47 (47)</option>
                                    <option value="48">:48 (48)</option>
                                    <option value="49">:49 (49)</option>
                                    <option value="50">:50 (50)</option>
                                    <option value="51">:51 (51)</option>
                                    <option value="52">:52 (52)</option>
                                    <option value="53">:53 (53)</option>
                                    <option value="54">:54 (54)</option>
                                    <option value="55">:55 (55)</option>
                                    <option value="56">:56 (56)</option>
                                    <option value="57">:57 (57)</option>
                                    <option value="58">:58 (58)</option>
                                    <option value="59">:59 (59)</option>
                                </select>
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="hour">小时</label>
                                <input id="hour" ng-model="cron_time.hour" type="text" class="form-control" size="4" ng-change="input_single_option('hour')" placeholder="小时">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="hour_options">快速选择</label>
                                <select id="hour_options" ng-model="options.hour" class="form-control" ng-change="select_single_option('hour')">
                                    <option value="">请选择</option>
                                    <option value="*">每小时(*)</option>
                                    <option value="*/2">每隔一小时(*/2)</option>
                                    <option value="*/3">每隔三小时(*/3)</option>
                                    <option value="*/4">每隔四小时(*/4)</option>
                                    <option value="*/6">每隔六小时(*/6)</option>
                                    <option value="0,12">每十二小时(0,12)</option>
                                    <option value="--" disabled>-- 小时 --</option>
                                    <option value="0">12:00 a.m.午夜(0)</option>
                                    <option value="1">1:00 a.m. (1)</option>
                                    <option value="2">2:00 a.m. (2)</option>
                                    <option value="3">3:00 a.m. (3)</option>
                                    <option value="4">4:00 a.m. (4)</option>
                                    <option value="5">5:00 a.m. (5)</option>
                                    <option value="6">6:00 a.m. (6)</option>
                                    <option value="7">7:00 a.m. (7)</option>
                                    <option value="8">8:00 a.m. (8)</option>
                                    <option value="9">9:00 a.m. (9)</option>
                                    <option value="10">10:00 a.m. (10)</option>
                                    <option value="11">11:00 a.m. (11)</option>
                                    <option value="12">12:00 p.m.中午(12)</option>
                                    <option value="13">1:00 p.m. (13)</option>
                                    <option value="14">2:00 p.m. (14)</option>
                                    <option value="15">3:00 p.m. (15)</option>
                                    <option value="16">4:00 p.m. (16)</option>
                                    <option value="17">5:00 p.m. (17)</option>
                                    <option value="18">6:00 p.m. (18)</option>
                                    <option value="19">7:00 p.m. (19)</option>
                                    <option value="20">8:00 p.m. (20)</option>
                                    <option value="21">9:00 p.m. (21)</option>
                                    <option value="22">10:00 p.m. (22)</option>
                                    <option value="23">11:00 p.m. (23)</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="day">天</label>
                                <input type="text" ng-model="cron_time.day" class="form-control" size="4" id="day" ng-change="input_single_option('day')" placeholder="天">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="day_options">快速选择</label>
                                <select id="day_options" ng-model="options.day" ng-change="select_single_option('day')" class="form-control">
                                    <option value="">请选择</option>
                                    <option value="*">每天(*)</option>
                                    <option value="*/2">每隔一天(*/2)</option>
                                    <option value="1,15">在每月的第 1 日和第 15 日(1,15)</option>
                                    <option value="--" disabled>-- 天 --</option>
                                    <option value="1">1 日 (1)</option>
                                    <option value="2">2 日 (2)</option>
                                    <option value="3">3 日 (3)</option>
                                    <option value="4">4 日 (4)</option>
                                    <option value="5">5 日 (5)</option>
                                    <option value="6">6 日 (6)</option>
                                    <option value="7">7 日 (7)</option>
                                    <option value="8">8 日 (8)</option>
                                    <option value="9">9 日 (9)</option>
                                    <option value="10">10 日 (10)</option>
                                    <option value="11">11 日 (11)</option>
                                    <option value="12">12 日 (12)</option>
                                    <option value="13">13 日 (13)</option>
                                    <option value="14">14 日 (14)</option>
                                    <option value="15">15 日 (15)</option>
                                    <option value="16">16 日 (16)</option>
                                    <option value="17">17 日 (17)</option>
                                    <option value="18">18 日 (18)</option>
                                    <option value="19">19 日 (19)</option>
                                    <option value="20">20 日 (20)</option>
                                    <option value="21">21 日 (21)</option>
                                    <option value="22">22 日 (22)</option>
                                    <option value="23">23 日 (23)</option>
                                    <option value="24">24 日 (24)</option>
                                    <option value="25">25 日 (25)</option>
                                    <option value="26">26 日 (26)</option>
                                    <option value="27">27 日 (27)</option>
                                    <option value="28">28 日 (28)</option>
                                    <option value="29">29 日 (29)</option>
                                    <option value="30">30 日 (30)</option>
                                    <option value="31">31 日 (31)</option>
                                </select>
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="month">月份</label>
                                <input type="text" ng-model="cron_time.month" class="form-control" size="4" id="month" ng-change="input_single_option('month')" placeholder="月份">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="month_options">快速选择</label>
                                <select id="month_options" ng-model="options.month" ng-change="select_single_option('month')" class="form-control">
                                    <option value="">请选择</option>
                                    <option value="*">每月(*)</option>
                                    <option value="*/2">每隔一月(*/2)</option>
                                    <option value="*/4">每隔三个月(*/4)</option>
                                    <option value="1,7">每六个月(1,7)</option>
                                    <option value="--" disabled>-- 个月 --</option>
                                    <option value="1">一月(1)</option>
                                    <option value="2">二月(2)</option>
                                    <option value="3">三月(3)</option>
                                    <option value="4">四月(4)</option>
                                    <option value="5">五月(5)</option>
                                    <option value="6">六月(6)</option>
                                    <option value="7">七月(7)</option>
                                    <option value="8">八月(8)</option>
                                    <option value="9">九月(9)</option>
                                    <option value="10">十月(10)</option>
                                    <option value="11">十一月(11)</option>
                                    <option value="12">十二月(12)</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="weekday">工作日</label>
                                <input type="text" ng-model="cron_time.weekday" class="form-control" size="4" id="weekday" ng-change="input_single_option('weekday')" placeholder="工作日">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="weekday_options">快速选择</label>
                                <select id="weekday_options" ng-model="options.weekday" class="form-control" ng-change="select_single_option('weekday')">
                                    <option value="">请选择</option>
                                    <option value="*">每天(*)</option>
                                    <option value="1-5">每个工作日(1-5)</option>
                                    <option value="0,6">每个周末(6,0)</option>
                                    <option value="1,3,5">每星期一、星期三和星期五(1,3,5)</option>
                                    <option value="2,4">每星期二和星期四(2,4)</option>
                                    <option value="--" disabled>--工作日--</option>
                                    <option value="0">星期日(0)</option>
                                    <option value="1">星期一(1)</option>
                                    <option value="2">星期二(2)</option>
                                    <option value="3">星期三(3)</option>
                                    <option value="4">星期四(4)</option>
                                    <option value="5">星期五(5)</option>
                                    <option value="6">星期六(6)</option>
                                </select>
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="task_user">用户</label>
                                <input type="text" ng-model="task_user" class="form-control" id="task_user" ng-disabled="task_id" placeholder="用户">
                            </div>
                            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <label for="task_user_options">选择用户</label>
                                <select class="form-control" ng-model="task_user" id="task_user_options" ng-disabled="task_id" ng-options="user for user in users">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                <label for="task_time">执行时间</label>
                                <input type="text" ng-model="task_time" class="form-control" id="task_time" placeholder="任务执行时间" readonly>
                            </div>
                            <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
                                <label for="task_command">执行命令</label>
                                <input type="text" ng-model="task_command" class="form-control" size="45" id="task_command" placeholder="任务执行命令">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" ng-show="task_id" ng-click="update_cron_jobs()">更新</button>
                <button class="btn btn-primary" ng-hide="task_id" ng-click="add_cron_jobs()">添加</button>
            </div>
        </div>
    </div>
</div>


<div id="cron-delete-confirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">删除任务 ？</h3>
            </div>
            <div class="modal-body">
                <p>确认删除当前任务？</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" ng-click="del_cron_jobs()">确定</button>
            </div>
        </div>
    </div>
</div>